import {useEffect, useState} from "react";

const App = () => {

    const [count, setCount] = useState(0)

    useEffect(() => {
        console.log("组件挂载执行")
    }, []);

    useEffect(() => {
        console.log("组件挂载执行+组件更新执行")
    });

    useEffect(() => {
        console.log("组件挂载执行+依赖性发生变化执行")
    }, [count])

    useEffect(() => {
        const time = setInterval(() => {
            console.log("组件挂载执行")
        }, 1000)
        // 返回一个函数用于清除副作用
        return () => {
            clearInterval(time)
            console.log("组件卸载执行")
        }
    }, [])

    return (
        <div className="App">
            <button onClick={() => setCount(count + 1)}>{count}</button>
        </div>
    )
}
export default App;
